/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utilidades;

import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JTextField;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.styles.MinimalBalloonStyle;

/**
 *
 * @author Lelouch
 */
public class ValidaEnteros extends KeyAdapter {
	JTextField tf;
	BalloonTip bt;

	public ValidaEnteros (JTextField tf) {
		this.tf = tf;
		        bt = new BalloonTip (tf, "Ingrese sólo números enteros positivos",
			new MinimalBalloonStyle (new Color (231, 225, 165), 2),
			BalloonTip.Orientation.LEFT_ABOVE, BalloonTip.AttachLocation.ALIGNED,
			20, 10, false);
		bt.setVisible (false);
	}

	@Override
	public void keyTyped (KeyEvent e) {
		bt.setVisible (false);
		char caracter = e.getKeyChar ();

		if ((caracter < '0' || caracter > '9') && (caracter != KeyEvent.VK_BACK_SPACE && caracter != KeyEvent.VK_DELETE)) {
			bt.setVisible (true);
			e.consume ();
		}
	}
}


